package me.caofeng.util;

import com.mysql.jdbc.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.print.DocFlavor;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * Copyright © 2017曹峰. All rights reserved.
 *
 * @Prject: mall
 * @Package: me.caofeng.util
 * @Description: 读取配置文件工具
 * @Author: 曹峰 blog.caofeng.me
 * @Date: 2017-06-21 23:26
 * @Version: V1.0
 */
public class PropertiesUtil {
    private static Logger LOGGER = LogManager.getLogger(PropertiesUtil.class);

    private static Properties properties;

    static {
        String fileName = "app.properties";
        properties = new Properties();
        try {
            properties.load(new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName), "UTF-8"));
        } catch (IOException e) {
            LOGGER.error(e);
        }
    }

    public static String getProperty(String key) {
        String value = (String) properties.get(key.trim());
        if (CheckUtil.isEmpty(key)) {
            return null;
        }
        return value.trim();
    }

    public static String getProperty(String key, String defaultValue) {
        String value = (String) properties.get(key.trim());
        if (CheckUtil.isEmpty(key)) {
            value = defaultValue;
        }
        return value.trim();
    }

    public static String getUrl(String host,String path){
        String url = "";
        switch (host){
            case Constant.IMAGE_HOST:
                url = getProperty(Constant.IMAGE_HOST,Constant.IMAGE_HOST_PATH)
                       + path;
                break;
        }

        return url;
    }
    public static void main(String[] args) {
        LOGGER.info("结果{},{}", 1, 23);
    }
}
